import { defineStore } from "pinia"

import { getProblems } from "@/api/login"

interface IProblemState {
  pro_id: string
  pro_description: string
  option_a: string
  option_b: string
  mold_description: string
  answer_a: string
  answer_b: string
}

export const useProblemStore = defineStore({
  id: "problem",
  state: (): IProblemState => {
    return {
      pro_id: "1",
      pro_description: "",
      option_a: "",
      option_b: "",
      mold_description: "",
      answer_a: "",
      answer_b: ""
    }
  },
  actions: {
    getProblem(idInfo: { pro_id: string }) {
      return new Promise((resolve, reject) => {
        getProblems({
          pro_id: idInfo.pro_id
        })
          .then((res: any) => {
            this.pro_id = res.data.pro_id
            this.pro_description = res.data.pro_description
            this.option_a = res.data.option_a
            this.option_b = res.data.option_b
            this.mold_description = res.data.mold_description
            this.answer_a = res.data.answer_a
            this.answer_b = res.data.answer_b
            resolve(true)
          })
          .catch((error) => {
            reject(error)
          })
      })
    }
  }
})
